package com.spring.sunflower.userinfo;

import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.LabelBean;
import com.spring.sunflower.bean.LoginByAuthCodeBean;
import com.spring.sunflower.common.CommonContract;
import com.spring.sunflower.constant.Constant;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/6/28<br/>
 * <p>
 * Describe:<br/>
 */
public class HobbyPresenter extends BasePresenter<CommonContract.HobbyView> {
    public HobbyPresenter(CommonContract.HobbyView baseView) {
        super(baseView);
    }

    public void getHobbyType() {
        Observable<LabelBean> observable = requestDataSource.requestLabel("visualizeLabel");
        addDisposable(observable, new BaseObserver<LabelBean>(baseView) {

            @Override
            public void onSuccess(LabelBean bean) {
                baseView.hideLoading();
                baseView.showHobby(bean.getDatas());
            }

            @Override
            public void onError(int status, String msg) {

            }
        });
    }

    public void register(String gender, String hobby,String nickname) {
        Observable<LoginByAuthCodeBean> observable = requestDataSource.register(gender, hobby,nickname);
        addDisposable(observable, new BaseObserver<LoginByAuthCodeBean>(baseView) {
            @Override
            public void onSuccess(LoginByAuthCodeBean bean) {
                baseView.hideLoading();
                LoginByAuthCodeBean.DatasBean datas = bean.getDatas();
                String token = datas.getToken();
                String sex = datas.getSex();
//                    Long birthday = datas.getBirthday();
                String sig = datas.getSig();
                String nickname = datas.getNickname();
                String type = datas.getType();
                String id = datas.getId();
                String photo = datas.getPhoto();
                String isVip = datas.getIsVip();
                String mobile = datas.getMobile();
                String wealth = datas.getWealth();

                saveField(Constant.KEY_TOKEN, token);
                saveField(Constant.KEY_GENDER, sex);
//                    saveField("birthday",birthday);
                saveField(Constant.KEY_SIGNATURE, sig);
                saveField(Constant.KEY_NICKNAME, nickname);
                saveField(Constant.KEY_TYPE, type);
                saveField(Constant.KEY_USERID, id.toString());
                saveField(Constant.KEY_PHOTO, photo);
                saveField(Constant.KEY_MOBILE, mobile);
                saveField(Constant.KEY_WEALTH, wealth);
                baseView.registerSucceed();


            }

            @Override
            public void onError(int status, String msg) {
                baseView.registerFailed(status, msg);
            }
        });

    }
}
